<?php


namespace app\admin\validate\member;
use think\validate;

class Member extends validate
{


    protected $rule =   [

        'username'  => ['require', 'alpha', 'unique'=>'member','length'=>'3,12'],
        'password'=>['require','confirm','length'=>'6,16'],
        'email'=>['email','requireIf'=>'type,1'],
        'phone'=>['mobile','requireIf'=>'type,1'],
        'min_order'=>['integer','requireIf'=>'type,2'],
        'max_order'=>['integer','requireIf'=>'type,2'],
        'type'=>['require'],
    ];

    protected $message  =   [

        'username.require'      => ['code' => 4012, 'msg' => '会员名称不能为空'],
        'username.unique'      => ['code' => 4013, 'msg' => '会员名称已经存在'],
        'username.alpha'      => ['code' => 4013, 'msg' => '会员名称只能是纯字母'],
        'username.length'      => ['code' => 4013, 'msg' => '会员名称长度3到12位'],
        'password.confirm'   => ['code' => 4015, 'msg' => '二次密码不一致'],
        'password.require'   => ['code' => 4015, 'msg' => '密码不能为空'],
        'type.require'   => ['code' => 4015, 'msg' => '类型必填'],
        'password.length'    => ['code' => 4016, 'msg' => '密码至少6-16位'],
        'email.requireIf'      => ['code' => 4019, 'msg' => '邮箱必填'],
        'min_order.requireIf'      => ['code' => 4019, 'msg' => '最小额度必填'],
        'max_order.requireIf'      => ['code' => 4019, 'msg' => '最大额度必填'],
        'min_order.integer'      => ['code' => 4019, 'msg' => '最小额度类型错误'],
        'max_order.integer'      => ['code' => 4019, 'msg' => '最大额度类型错误'],
        'email.email'      => ['code' => 4019, 'msg' => '邮箱格式错误'],
        'phone.requireIf'   => ['code' => 4015, 'msg' => '手机号码必填'],
        'phone.mobile'   => ['code' => 4018, 'msg' => '手机号码格式有误'],
    ];
    // edit 验证场景定义
    public function sceneModify()
    {
        return $this->remove('password',true)->remove('username',true);
    }

    // edit 验证场景定义
    public function sceneLogin()
    {
        return $this->only(['username','password'])->remove(['username'=>'unique','password'=>'confirm']);
    }
}